<template>
  <el-container class="layout-container-demo" style="height: 100vh">
    <el-aside width="200px">
      <el-scrollbar>
        <el-menu :default-openeds="['1', '2', '3']">
          <el-sub-menu index="1">
            <template #title>
              <el-icon><message /></el-icon>商店管理
            </template>
            <el-menu-item-group>
              <el-menu-item index="1-1" @click="ShopInfo">商家信息</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-sub-menu index="2">
            <template #title>
              <el-icon><icon-menu /></el-icon>商品管理
            </template>
            <el-menu-item-group>
              <el-menu-item index="2-1" @click="GoodsInfo">商品信息</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-sub-menu index="3">
            <template #title>
              <el-icon><setting /></el-icon>用户管理
            </template>
            <el-menu-item-group>
              <el-menu-item index="3-1" @click="UserInfo">用户信息</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-sub-menu index="4">
            <template #title>
              <el-icon><setting /></el-icon>折扣管理
            </template>
            <el-menu-item-group>
              <el-menu-item index="4-1" @click="DiscountInfo">折扣信息</el-menu-item>
              <el-menu-item index="4-3" @click="DisSend">发放折扣</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
        </el-menu>
      </el-scrollbar>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 14px">
        <div class="toolbar">
          <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px"><setting /></el-icon>
            <el-icon><Setting /></el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="Logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>{{ username }}</span>
        </div>
      </el-header>

      <el-main>
        <el-scrollbar class="router_view">
          <router-view></router-view>
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts" setup>
import axios from "axios";
import { ref, onMounted } from "vue";
import { Menu as IconMenu, Message, Setting } from "@element-plus/icons-vue";
import router from "@/router";
import { ElMessage } from "element-plus";

const username = ref("");
function getUserInfo() {
  const uid = localStorage.getItem("admin_id");
  axios
    .get("/api/admin/get?uid=" + uid)
    .then((res) => {
      console.log(res);
      if (res.data.success) {
        if (res.data.message.account) {
          username.value = res.data.message.account;
        } else {
          username.value = res.data.message.username;
        }
      } else {
        router.push("/auth/login");
      }
    })
    .catch((err) => {
      console.log(err);
    });
}
const Logout = () => {
  localStorage.removeItem("admin_id");
  ElMessage({
    message: "退出登录成功",
    type: "success",
  });
  setTimeout(() => {
    router.push("/");
  }, 800);
};
const ShopInfo = () => {
  router.push("/manager/shop");
};
const GoodsInfo = () => {
  router.push("/manager/goods");
};
const UserInfo = () => {
  router.push("/manager/user");
};
const DiscountInfo = () => {
  router.push("/manager/discount");
};

const DisSend = () => {
  router.push("/manager/sendDiscount");
};
getUserInfo();
</script>

<style scoped>
.layout-container-demo .el-header {
  position: relative;
  color: var(--el-text-color-primary);
}
.layout-container-demo .el-aside {
  color: var(--el-text-color-primary);
}
.layout-container-demo .el-menu {
  border-right: none;
}
.layout-container-demo .el-main {
  padding: 0;
}
.layout-container-demo .toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}
.router_view {
}
</style>
